package troqler;

import java.io.Serializable;
import java.util.Locale;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;

@Named
@SessionScoped
public class LocaleBean implements Serializable {

  private String lang;
  private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

  public Locale getLocale() {
    return locale;
  }

  public String getLocaleString() {
    return this.getLocale().toString();
  }

  public String getLanguage() {
    return locale.getLanguage();
  }

  public void changeLang(String lang) {
    FacesContext context = FacesContext.getCurrentInstance();
    this.lang = lang;
    if (!(this.lang == null || this.lang.isEmpty())) {
      locale = new Locale(lang);
      context.getViewRoot().setLocale(locale);
      System.out.println(this.getLocale().toString());
    }
  }  
}
